# -*- coding: UTF-8 -*-
from django.contrib import admin
from django.utils.translation import gettext_lazy as _
from .models import MaterialCategory, Material, MaterialAttribute


@admin.register(MaterialCategory)
class MaterialCategoryAdmin(admin.ModelAdmin):
    list_display = ['name', 'code', 'description', 'parent', 'created_at']
    list_display_links = ['name']
    search_fields = ['name', 'code', 'description']
    list_filter = ['parent', 'created_at']
    date_hierarchy = 'created_at'
    
    fieldsets = (
        (_('基本信息'), {
            'fields': ('name', 'code', 'description', 'parent')
        }),
    )


@admin.register(Material)
class MaterialAdmin(admin.ModelAdmin):
    list_display = ['name', 'code', 'category', 'unit', 'price', 'supplier', 'created_at']
    list_display_links = ['name']
    search_fields = ['name', 'code', 'description']
    list_filter = ['category', 'unit', 'supplier', 'created_at']
    date_hierarchy = 'created_at'
    
    fieldsets = (
        (_('基本信息'), {
            'fields': ('name', 'code', 'category', 'description')
        }),
        (_('规格信息'), {
            'fields': ('unit', 'price', 'supplier')
        }),
        (_('其他信息'), {
            'fields': ('note',),
            'classes': ('collapse',)
        }),
    )


@admin.register(MaterialAttribute)
class MaterialAttributeAdmin(admin.ModelAdmin):
    list_display = ['material', 'attribute', 'value', 'created_at']
    list_filter = ['attribute', 'created_at']
    search_fields = ['material__name', 'attribute__name', 'value']
    date_hierarchy = 'created_at'
    
    fieldsets = (
        (_('属性信息'), {
            'fields': ('material', 'attribute', 'value')
        }),
    )